package sessionBean;

import interfaceBeanRemote.SessionAdministrateurRemote;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entityBean.Administrateur;

/**
 * Session Bean implementation class sessionAdministrateur
 */
@Stateless
public class SessionAdministrateur implements SessionAdministrateurRemote {
	@PersistenceContext(unitName = "EJB3_Entity")
	EntityManager em;

	@PostConstruct
	public void init() {
		System.out.println("calling init method");
	}

	@PreDestroy
	public void cleanup() {
		System.out.println("calling cleanup method");
	}

	/**
	 * Default constructor.
	 */
	public SessionAdministrateur() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public Administrateur addAdministrateur(Administrateur admin) {
		em.persist(admin);
		return admin;
	}

	public String findLogin(String login) {

		Administrateur administrateur = em.find(Administrateur.class, login);
		return administrateur.getLogin();
	}

	public String findPassword(String login) {

		Administrateur administrateur = em.find(Administrateur.class, login);
		return administrateur.getPassWord();
	}

}
